﻿using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

using Com.Ompchina.Lib.DBHelper;
using IDAL.Common;
using IDAL;
using Model.Common;
namespace SQLServerDAL.Common
{
    /// <summary>
    /// 数据层，通用版块，省份
    /// </summary>
    public class ProvinceDAL : DalBase, IProvince
    {
        public ProvinceDAL() 
        {
            Schema = "cms.";
            TableName = "Province";
            Fields = "ProvinceID, ProvinceName, HasInfo";
        }

        #region IProvince 成员
        /// <summary>
        /// 省份列表
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<ProvinceInfo> ListProvince(ProvinceCondition condition)
        {
            SqlBuilder = new StringBuilder("SELECT ");
            SqlBuilder.AppendFormat(" {0} FROM {1} WHERE 1 = 1 ", Fields, Schema + TableName);
            if (!string.IsNullOrEmpty(condition.HasInfo))
                SqlBuilder.AppendFormat(" AND HasInfo = '{0}'", condition.HasInfo);
            SqlDataReader dr = SqlHelper.ExecuteReader(base.ConnectionString, CommandType.Text, SqlBuilder.ToString());
            List<ProvinceInfo> list = new List<ProvinceInfo>();
            if (dr != null) 
            {
                while (dr.Read()) 
                {
                    int i = 0;
                    ProvinceInfo info = new ProvinceInfo();
                    info.ProvinceID = dr.GetInt32(i++);
                    info.ProvinceName = dr.GetString(i++);
                    info.HasInfo = dr.GetString(i++);
                    list.Add(info);
                }
                dr.Close();
            }
            return list;
        }
        #endregion
    }
}
